import { Models } from '../../../../common/typings/model'
import Config from '../../../../config/Config'
import KoaRouter from 'koa-router'
import Mysql from '../../../../core/Mysql'
import { Success } from '../../../../core/HttpException'
import validator from '../../../../middlewares/validator'
import Auth from '../../../../middlewares/Auth'
import deleteRoleByIds from '../../../../common/apiValidate/system/role/delete'
import RedisClient from '../../../../core/Redis'

const router = new KoaRouter({
  prefix: `${Config.api_prefix}system/role`,
})

/*
 * 删除菜单
 * @return
 */
router.get('/delete', Auth.verifyTokenPermission, validator(deleteRoleByIds), async (ctx: Models.Ctx) => {
  const { ids } = ctx.request.query
  await Mysql.command(`
    DELETE
    FROM
      role
    WHERE
      FIND_IN_SET(id, '${ids}')
  `)
  Auth.updateRedisRole()
  throw new Success()
})

export default router
